// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.Collections;

import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public abstract class ZomboidAbstractMap<K, V> implements Map<K, V> {
    transient volatile Set<K> keySet = null;
    transient volatile Collection<V> values = null;

    protected ZomboidAbstractMap() {
    }

    public int size() {
        return this.entrySet().size();
    }

    public boolean isEmpty() {
        return this.size() == 0;
    }

    public boolean containsValue(Object value) {
        Iterator iterator = this.entrySet().iterator();
        if (value == null) {
            while (iterator.hasNext()) {
                Entry entry0 = (Entry)iterator.next();
                if (entry0.getValue() == null) {
                    return true;
                }
            }
        } else {
            while (iterator.hasNext()) {
                Entry entry1 = (Entry)iterator.next();
                if (value.equals(entry1.getValue())) {
                    return true;
                }
            }
        }

        return false;
    }

    public boolean containsKey(Object key) {
        Iterator iterator = this.entrySet().iterator();
        if (key == null) {
            while (iterator.hasNext()) {
                Entry entry0 = (Entry)iterator.next();
                if (entry0.getKey() == null) {
                    return true;
                }
            }
        } else {
            while (iterator.hasNext()) {
                Entry entry1 = (Entry)iterator.next();
                if (key.equals(entry1.getKey())) {
                    return true;
                }
            }
        }

        return false;
    }

    public V get(Object object) {
        Iterator iterator = this.entrySet().iterator();
        if (object == null) {
            while (iterator.hasNext()) {
                Entry entry0 = (Entry)iterator.next();
                if (entry0.getKey() == null) {
                    return (V)entry0.getValue();
                }
            }
        } else {
            while (iterator.hasNext()) {
                Entry entry1 = (Entry)iterator.next();
                if (object.equals(entry1.getKey())) {
                    return (V)entry1.getValue();
                }
            }
        }

        return null;
    }

    public V put(K var1, V var2) {
        throw new UnsupportedOperationException();
    }

    public V remove(Object object0) {
        Iterator iterator = this.entrySet().iterator();
        Entry entry0 = null;
        if (object0 == null) {
            while (entry0 == null && iterator.hasNext()) {
                Entry entry1 = (Entry)iterator.next();
                if (entry1.getKey() == null) {
                    entry0 = entry1;
                }
            }
        } else {
            while (entry0 == null && iterator.hasNext()) {
                Entry entry2 = (Entry)iterator.next();
                if (object0.equals(entry2.getKey())) {
                    entry0 = entry2;
                }
            }
        }

        Object object1 = null;
        if (entry0 != null) {
            object1 = entry0.getValue();
            iterator.remove();
        }

        return (V)object1;
    }

    public void putAll(Map<? extends K, ? extends V> m) {
        for (Entry entry : m.entrySet()) {
            this.put((K)entry.getKey(), (V)entry.getValue());
        }
    }

    public void clear() {
        this.entrySet().clear();
    }

    public Set<K> keySet() {
        if (this.keySet == null) {
            this.keySet = new AbstractSet<K>() {
                public Iterator<K> iterator() {
                    return new Iterator<K>() {
                        private Iterator<Entry<K, V>> i = ZomboidAbstractMap.this.entrySet().iterator();

                        public boolean hasNext() {
                            return this.i.hasNext();
                        }

                        public K next() {
                            return (K)((Entry)this.i.next()).getKey();
                        }

                        public void remove() {
                            this.i.remove();
                        }
                    };
                }

                public int size() {
                    return ZomboidAbstractMap.this.size();
                }

                public boolean contains(Object object) {
                    return ZomboidAbstractMap.this.containsKey(object);
                }
            };
        }

        return this.keySet;
    }

    public Collection<V> values() {
        if (this.values == null) {
            this.values = new AbstractCollection<V>() {
                public Iterator<V> iterator() {
                    return new Iterator<V>() {
                        private Iterator<Entry<K, V>> i = ZomboidAbstractMap.this.entrySet().iterator();

                        public boolean hasNext() {
                            return this.i.hasNext();
                        }

                        public V next() {
                            return (V)((Entry)this.i.next()).getValue();
                        }

                        public void remove() {
                            this.i.remove();
                        }
                    };
                }

                public int size() {
                    return ZomboidAbstractMap.this.size();
                }

                public boolean contains(Object object) {
                    return ZomboidAbstractMap.this.containsValue(object);
                }
            };
        }

        return this.values;
    }

    public abstract Set<Entry<K, V>> entrySet();

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Map map)) {
            return false;
        } else if (map.size() != this.size()) {
            return false;
        } else {
            try {
                for (Entry entry : this.entrySet()) {
                    Object object0 = entry.getKey();
                    Object object1 = entry.getValue();
                    if (object1 == null) {
                        if (map.get(object0) != null || !map.containsKey(object0)) {
                            return false;
                        }
                    } else if (!object1.equals(map.get(object0))) {
                        return false;
                    }
                }

                return true;
            } catch (ClassCastException classCastException) {
                return false;
            } catch (NullPointerException nullPointerException) {
                return false;
            }
        }
    }

    public int hashCode() {
        int _int = 0;
        Iterator iterator = this.entrySet().iterator();

        while (iterator.hasNext()) {
            _int += ((Entry)iterator.next()).hashCode();
        }

        return _int;
    }

    public String toString() {
        Iterator iterator = this.entrySet().iterator();
        if (!iterator.hasNext()) {
            return "{}";
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append('{');

            while (true) {
                Entry entry = (Entry)iterator.next();
                Object object0 = entry.getKey();
                Object object1 = entry.getValue();
                stringBuilder.append(object0 == this ? "(this Map)" : object0);
                stringBuilder.append('=');
                stringBuilder.append(object1 == this ? "(this Map)" : object1);
                if (!iterator.hasNext()) {
                    return stringBuilder.append('}').toString();
                }

                stringBuilder.append(", ");
            }
        }
    }

    protected Object clone() throws CloneNotSupportedException {
        ZomboidAbstractMap zomboidAbstractMap0 = (ZomboidAbstractMap)super.clone();
        zomboidAbstractMap0.keySet = null;
        zomboidAbstractMap0.values = null;
        return zomboidAbstractMap0;
    }

    private static boolean eq(Object object0, Object object1) {
        return object0 == null ? object1 == null : object0.equals(object1);
    }

    public static class SimpleEntry<K, V> implements Entry<K, V>, Serializable {
        private static final long serialVersionUID = -8499721149061103585L;
        private final K key;
        private V value;

        public SimpleEntry(K object0, V object1) {
            this.key = (K)object0;
            this.value = (V)object1;
        }

        public SimpleEntry(Entry<? extends K, ? extends V> entry) {
            this.key = (K)entry.getKey();
            this.value = (V)entry.getValue();
        }

        public K getKey() {
            return this.key;
        }

        public V getValue() {
            return this.value;
        }

        public V setValue(V object1) {
            Object object0 = this.value;
            this.value = (V)object1;
            return (V)object0;
        }

        public boolean equals(Object o) {
            return !(o instanceof Entry entry) ? false : ZomboidAbstractMap.eq(this.key, entry.getKey()) && ZomboidAbstractMap.eq(this.value, entry.getValue());
        }

        public int hashCode() {
            return (this.key == null ? 0 : this.key.hashCode()) ^ (this.value == null ? 0 : this.value.hashCode());
        }

        public String toString() {
            return this.key + "=" + this.value;
        }
    }

    public static class SimpleImmutableEntry<K, V> implements Entry<K, V>, Serializable {
        private static final long serialVersionUID = 7138329143949025153L;
        private final K key;
        private final V value;

        public SimpleImmutableEntry(K object0, V object1) {
            this.key = (K)object0;
            this.value = (V)object1;
        }

        public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
            this.key = (K)entry.getKey();
            this.value = (V)entry.getValue();
        }

        public K getKey() {
            return this.key;
        }

        public V getValue() {
            return this.value;
        }

        public V setValue(V var1) {
            throw new UnsupportedOperationException();
        }

        public boolean equals(Object o) {
            return !(o instanceof Entry entry) ? false : ZomboidAbstractMap.eq(this.key, entry.getKey()) && ZomboidAbstractMap.eq(this.value, entry.getValue());
        }

        public int hashCode() {
            return (this.key == null ? 0 : this.key.hashCode()) ^ (this.value == null ? 0 : this.value.hashCode());
        }

        public String toString() {
            return this.key + "=" + this.value;
        }
    }
}
